﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core
{
    public static partial class msg
    {
        public static dynamic addOrEditDSNotice(int? nid, string title, string color, string content)
        {
            var sql = new Sql.SqlDataContext();
            Sql.DSNotice n;
            if (nid != null)
            {
                n = sql.DSNotice.FirstOrDefault(row => row.nid == nid);
                if (n == null) return new
                    {
                        success = false,
                        msg = "公告不存在"
                    };
            }
            else
            {
                n = new Sql.DSNotice();
                n.time = DateTime.Now;
            }
            n.title = title;
            n.color = color;
            n.content = content;
            if (nid == null) sql.DSNotice.InsertOnSubmit(n);
            sql.SubmitChanges();
            return new
            {
                success = true,
                n.nid
            };
        }
	}
}